/* SVN FILE: $Id: downstream.js 65 2011-12-19 16:57:25Z lga $ */

var downstream = function (selector) {
	'use strict';
	var domain = "http://www.visitncwine.com", ignore = ['google.com', 'yahoo.com', 'bing.com'];
	if (window.location.host === 'dev.m.visitncwine.com') {
		domain = "http://winedev.op-ip.com";
	}
	ignore.push(window.location.host);
	if (selector === undefined) {
		selector = "a";
	}
	x$(selector).click(function (e) {
		var i, log = true, url;
		if (this.href && this.href.indexOf('://') !== -1) {
			for (i = 0; i < ignore.length; i++) {
				if (this.href.indexOf(ignore[i]) !== -1) {
					return true;
				}
			}
			e.preventDefault();
			x$(this).un('click');
			url = domain + "/referrals/track/?l=" + escape(this.href) + '&rd=' + escape(window.location.host);
			if (x$(this).attr("data-uid").length > 0) {
				url = url + '&uid=' + escape(x$(this).attr("data-uid")[0]);
			}
			window.open(url, this.target || '_self');
			return false;
		}
		return true;
	});
};
x$.ready(downstream);